package com.fau.cm.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

import com.fau.cm.util.SystemConfig;

/**
 * @desc 订单产品表
 * @author liy
 * @datetime 2014年9月12日,下午2:37:26
 */
@Entity
@Table(name = "medical_orders_product")
public class MedicalOrdersProduct implements Serializable, JSONAware{

	private static final long serialVersionUID = 2355407232115888525L;

	private String id;
	private BigDecimal freight;		// 运费
	private BigDecimal prePrice;	// 优惠价格
	private BigDecimal price;		// 价格
	private BigDecimal totalPrice;	// 实际价格
	private BigDecimal discountPrice;	// 折扣价
	private Integer quantity;		// 数量
	private Integer usePoints;		// 使用积分
	private Integer useRed;			// 使用红包
	private String ordersId;		// 订单id
	
	private Date createTime = new Date();	// 创建时间
	private Date updateTime = new Date();	// 修改时间
	
	private String medicineId;				// 药品id
	private MedicalMedicine medicine;		// 药品实体类
	
	private String hospitalId;		// 医药id
	private String keyType;			// 字典表类型
	private String keyPid;			// 字典表父id
	private String medName;			// 药品名称
	private String medType;			// 药品类型（普通产品、搭销、赠品）
	private String medSort;			// 药品类别
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}
	
	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "freight", length = 11)
	public BigDecimal getFreight() {
		return freight;
	}

	public void setFreight(BigDecimal freight) {
		this.freight = freight;
	}
	
	@Column(name = "pre_price", length = 11)
	public BigDecimal getPrePrice() {
		return prePrice;
	}

	public void setPrePrice(BigDecimal prePrice) {
		this.prePrice = prePrice;
	}
	
	@Column(name = "price", length = 11)
	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	@Column(name = "total_price", length = 11)
	public BigDecimal getTotalPrice() {
		return totalPrice;
	}

	public void setTotalPrice(BigDecimal totalPrice) {
		this.totalPrice = totalPrice;
	}
	
	@Column(name = "discount_price", length = 11)
	public BigDecimal getDiscountPrice() {
		return discountPrice;
	}

	public void setDiscountPrice(BigDecimal discountPrice) {
		this.discountPrice = discountPrice;
	}

	@Column(name = "quantity", length = 11)
	public Integer getQuantity() {
		return quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	@Column(name = "use_points", length = 11)
	public Integer getUsePoints() {
		return usePoints;
	}

	public void setUsePoints(Integer usePoints) {
		this.usePoints = usePoints;
	}

	@Column(name = "use_red", length = 11)
	public Integer getUseRed() {
		return useRed;
	}

	public void setUseRed(Integer useRed) {
		this.useRed = useRed;
	}
	
	@Column(name = "orders_id", length = 32)
	public String getOrdersId() {
		return ordersId;
	}

	public void setOrdersId(String ordersId) {
		this.ordersId = ordersId;
	}
	
	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "update_time")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@Transient
	public String getMedicineId() {
		return medicineId;
	}

	public void setMedicineId(String medicineId) {
		this.medicineId = medicineId;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "medicine_id")
	public MedicalMedicine getMedicine() {
		return medicine;
	}

	public void setMedicine(MedicalMedicine medicine) {
		this.medicine = medicine;
	}

	@Transient
	public String getHospitalId() {
		return hospitalId;
	}

	public void setHospitalId(String hospitalId) {
		this.hospitalId = hospitalId;
	}
	
	@Transient
	public String getKeyType() {
		return keyType;
	}

	public void setKeyType(String keyType) {
		this.keyType = keyType;
	}

	@Transient
	public String getKeyPid() {
		return keyPid;
	}

	public void setKeyPid(String keyPid) {
		this.keyPid = keyPid;
	}

	@Transient
	public String getMedName() {
		return medName;
	}

	public void setMedName(String medName) {
		this.medName = medName;
	}

	@Transient
	public String getMedType() {
		return medType;
	}

	public void setMedType(String medType) {
		this.medType = medType;
	}

	@Transient
	public String getMedSort() {
		return medSort;
	}

	public void setMedSort(String medSort) {
		this.medSort = medSort;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("medicineName", medicine.getName());
		if(SystemConfig.MEDICINE_GENERAL_TYPE.equals(medicine.getMedicineType())) {
			obj.put("ridePin", "否");
			obj.put("premiums", "否");
		}else if(SystemConfig.MEDICINE_RIDEPIN_TYPE.equals(medicine.getMedicineType())){ 	// 搭销
			obj.put("ridePin", "是");
			obj.put("premiums", "否");
		}else {
			obj.put("premiums", "是");
			obj.put("ridePin", "否");
		}
		obj.put("price", price);
		obj.put("freight", freight);
		obj.put("prePrice", prePrice);
		obj.put("totalPrice", totalPrice);
		obj.put("quantity", quantity);
		obj.put("usePoints", usePoints);
		obj.put("useRed", useRed);
		obj.put("discountPrice", discountPrice);
		
		return obj.toString();
	}
}
